package com.atguigu.gulimall.product.web;

import com.atguigu.gulimall.product.entity.CategoryEntity;
import com.atguigu.gulimall.product.service.CategoryService;
import com.atguigu.gulimall.product.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    CategoryService categoryService;
    @GetMapping({"/","/index.html"})
    public String indexPage(Model model){
        List<CategoryEntity> categoryEntities=categoryService.cagetLevel1Categorys();
        model.addAttribute("categories",categoryEntities);
//        thymeleaf配置文件中有默认寻找的html页面的路径
        return "index";
    }

    /**
     * 怎么调用这个方法的：gulimall.com->gulimall-product->/->index.html(中引入了.js文件，下面一行所示。)->catalogLoader.js文件中调用了这个url
     * <script type="text/javascript" src="/static/index/js/catalogLoader.js"></script>
     * @return
     */
    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String, List<Catelog2Vo>> getCatalogJson(){
        Map<String,  List<Catelog2Vo>> map=categoryService.getCatalogJson();
        return map;
    }
}
